package com.example.xgakj.securityguard.ui.activities;

import android.os.Bundle;

import com.example.xgakj.mylibrary.mvp.utils.SharedPreferencesUtil;
import com.example.xgakj.securityguard.R;
import com.example.xgakj.securityguard.base.BaseActivity;
import com.example.xgakj.securityguard.base.Parameters;
import com.socks.library.KLog;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.BiFunction;
import io.reactivex.schedulers.Schedulers;

public class SplashActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        Observable.just(3, 2, 1).zipWith(Observable.interval(0, 1, TimeUnit.SECONDS), new BiFunction<Integer, Long, String>() {
            @Override
            public String apply(@NonNull Integer integer, @NonNull Long aLong) throws Exception {
                return String.valueOf(integer);
            }
        })
                .observeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        addSubscription(d);
                    }

                    @Override
                    public void onNext(@NonNull String s) {
                        KLog.d(s);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        KLog.d("onError");
                    }

                    @Override
                    public void onComplete() {
                        checkLogin();
                    }
                });



    }

    private void checkLogin() {
        boolean auto_login = SharedPreferencesUtil.getBoolean(mContex, Parameters.AUTO_LOGIN, false);
        if (auto_login){

        }

    }
}
